@extends("admin.layout.main")

@section("content")

    <style>
        table thead tr th {
            text-align: center
        }

        table tbody tr td {
            text-align: center
        }
    </style>
    <div class="page-header">
        <h1>
            创客财务
        </h1>
    </div>
    <div class="page-header">
        <form action="">
            <a onclick="downLoad()" class="btn btn-xs btn-success" style="margin-right: 20px;">导出</a>
            <label>
                变动类型：
                <select name="record_type">
                    <option value="0">全部</option>
                    <option value="2" @if($where['record_type']==2) selected @endif>注册币</option>
                    <option value="1" @if($where['record_type']==1) selected @endif>积分</option>
                </select>
            </label>
            <label>
                交易结果：
                <select name="status" id="">
                    <option value="0">全部</option>
                    <option value="1" @if($where['status']==1) selected @endif>成功</option>
                    <option value="2" @if($where['status']==2) selected @endif>失败</option>
                </select>
            </label>
            <label>
                创客ID：
                <input type="text" name="keyword" value="{{ $where['keyword'] }}">
            </label>
            <label>
                下单日期：
                <input type="text" id="start_time" name="start_time" value="{{ $where['start_time'] }}">
                至
                <input type="text" id="end_time" name="end_time" value="{{ $where['end_time'] }}">
            </label>
            <button class="btn btn-xs btn-primary">搜索</button>
        </form>
    </div>


    <!-- div.table-responsive -->

    <!-- div.dataTables_borderWrap -->
    <div>
        <table id="" class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>时间</th>
                <th>创客ID</th>
                <th>手机号码</th>
                <th>流水号</th>
                <th>变动类型</th>
                <th>财务类型</th>
                <th>交易方式</th>
                <th>变动金额</th>
                <th>交易结果</th>
                <th>变动后金额</th>
            </tr>
            </thead>

            <tbody id="data">
                @foreach($data as $v)
                    <tr>
                        <td>{{ $v->created_at }}</td>
                        <td>{{ $v->user['id'] }}</td>
                        <td>{{ $v->user['mobile'] }}</td>
                        <td>{{ $v->trade_no }}</td>
                        <td>@if($v->record_type==1)积分@else注册币 @endif</td>
                        <td>@if($v->income==1)收入@else支出 @endif</td>
                        <td>{{ $typeArr[$v->type] }}</td>
                        <td>{{ $v->cash }}</td>
                        <td>{{ $statusArr[$v->status] }}</td>
                        <td>{{ $v->after_cash }}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
        <div class="pagination pagination-centered">
            {{ $data->appends($where)->links('admin.layout.page') }}
        </div>
    </div>
    <link rel="stylesheet" href="/plugins/jedate/jedate.css"/>
    <script src="/plugins/jedate/jedate.min.js"></script>
    <script src="/plugins/layui/layui.js"></script>
    <script src="/plugins/layui/layui_component.js"></script>
    <script>
        function downLoad() {
            var length = $('#data').find('tr').length;
            if(length <= 0){
                showMessage('暂无数据可导！',0);
                return false;
            }
            var record_type = '{{ $where['record_type'] }}';
            var keyword = '{{ $where['keyword'] }}';
            var status = '{{ $where['status'] }}';
            var start_time = '{{ $where['start_time'] }}';
            var end_time = '{{ $where['end_time'] }}';
            window.location.href = "{{ url('/admin/finance/downList') }}?record_type=" + record_type + "&status=" + status + "&keyword=" + keyword + "&start_time=" + start_time + "&end_time=" + end_time;
        }
        var start = {
            dateCell: "#start_time",
            format: "YYYY-MM-DD",
            isinitVal: false,
            isTime: false, //isClear:false,
            maxDate: "{{ $where['end_time'] }}",
            minDate: "",
            choosefun: function (datas) {
                end.minDate = datas;
                $("input[name='begin']").val(datas);
            }
        };
        jeDate(start);
        var end = {
            dateCell: "#end_time",
            format: "YYYY-MM-DD",
            isinitVal: false,
            isTime: false, //isClear:false,
            maxDate: "2099-01-01 23:59:59",
            minDate: "{{ $where['start_time'] }}",
            choosefun: function (datas) {
                start.maxDate = datas;
                $("input[name='end']").val(datas);
            }
        };
        jeDate(end);
    </script>
@endsection